<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 17-11-2
 * Time: 下午9:29
 */

$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_bind($socket,'0.0.0.0','4481');
socket_listen($socket);

do{
    $conn = socket_accept($socket);
    socket_set_nonblock($conn);

    try{
retry:
        $msg = socket_read($conn,1024);

        $error = socket_last_error($conn);
        if($error > 0){
            echo 'error2:',PHP_EOL;
            var_dump($error);
            var_dump(socket_strerror($error));

            if($error == 11){
                goto retry;
            }
        }
    }catch (\Error $e){
        echo 'error:',PHP_EOL;
        var_dump($e);
    }
    socket_close($conn);

}while(true);